
package com.compuvest.tld;

// <editor-fold defaultstate="collapsed" desc="import">
import javax.servlet.http.HttpServletRequest;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;

import com.compuvest.web.Basket;
// </editor-fold>

public class Head extends TagSupport {

    protected String pageName;

// <editor-fold defaultstate="collapsed" desc="doStartTag()">

    @Override
    public int doStartTag() throws JspException {

        StringBuilder line = new StringBuilder(2200);
        try {
            String checkoutURL = pageContext.getServletContext().getInitParameter("https") + "CustomerForm.jsp";
            String serverName = pageContext.getServletContext().getInitParameter("http");
            String infoLink = pageContext.getServletContext().getInitParameter("info");
            Basket basket = (Basket)pageContext.getSession().getAttribute("basket");

            line.append("<div id='cv_head'>");
            line.append("<form name='SearchForm' action='").append(serverName).append("ItemsSearch.jsp").append("' method=POST>\n");
            line.append("<table id='tb1'>");
            line.append("<tr>");
            line.append("<td><a href='").append(serverName).append("'><img src='../images/h/fup.jpg' border=0></a></td>");
            line.append("<td style='width:100%;'></td>");
            line.append("<td><img src='../images/h/bsk.gif'></td>");

            if(basket.size() == 0) {
                line.append("<td class='cv_bsk'>");
                line.append("&nbsp;&nbsp;ITEMS: 0 TOTAL: $0.00");
            }
            else {
                line.append("<td class='cv_bsk' onclick=\"location.href='").append(serverName).append("Basket.jsp").append("'\">");
                line.append("&nbsp;&nbsp;<font color='red'>ITEMS: ").append(basket.size()).append(" TOTAL: ");
                line.append(String.format("$%,.2f", basket.getTempTotal())).append("</font>");

            }
            line.append("&nbsp;&nbsp;</td>");

            line.append("<td><a class='cv_lmy' href='").append(checkoutURL).append("'></a></td>");
            line.append("<td><a class='cv_lch' href='").append(checkoutURL).append("'></a></td>");
            line.append("</tr>");
            line.append("</table>");
            line.append("<table id='tb2'>");
            line.append("<tr>");
            line.append("<td><a href='").append(serverName).append("'><img src='../images/h/fph.gif' border=0></a>");
            line.append("<td><img src='../images/h/ch_bl.jpg'></td>"); // ch_on.jpg
            line.append("<td style='width:100%;'></td>");
            line.append("<td></td>");
            line.append("</tr>");
            line.append("</table>");
            line.append("<table id='tb3'>");
            line.append("<tr>");
            line.append("<td><img src='../images/h/fbt.jpg'></td>");
            line.append("<td style='width:100%;'></td>");
            line.append("<td><a class='cv_lau' href='").append(infoLink).append("AboutUs.jsp").append("'></a></td>");
            line.append("<td><a class='cv_lcs' href='").append(infoLink).append("CustomerService.jsp").append("'></a></td>");
            line.append("<td><a class='cv_lrs' href='").append(infoLink).append("Resellers.jsp").append("'></a></td>");
            line.append("<td><a class='cv_lcu' href='").append(infoLink).append("ContactUs.jsp").append("'></a></td>");
            line.append("</tr>");
            line.append("</table>");
            line.append("<table id='tb4'>");
            line.append("<tr>");
            line.append("<td><a class='cv_lna' href='").append(serverName).append("ItemsNewarrival.jsp").append("'></a></td>");
            line.append("<td><a class='cv_lco' href='").append(serverName).append("ItemsCloseout.jsp").append("'></a></td>");
            line.append("<td><a class='cv_lhd' href='").append(serverName).append("ItemsHotdeals.jsp").append("'></a></td>");
            line.append("<td><a class='cv_lbi' href='").append(serverName).append("'></a></td>");
            line.append("<td><a class='cv_lai' href='").append(serverName).append("ItemsAll.jsp").append("'></a></td>");
//            line.append("<td><h3>").append(System.getProperty("com.sun.aas.instanceName")).append("</h3></td>");
            line.append("<td style='width:100%;'></td>");
            line.append("<td>");

            String h_search = ((HttpServletRequest)pageContext.getRequest()).getParameter("Search");
            if(h_search == null) h_search = "SEARCH";
            int searchID = 1;
            try { searchID = Integer.parseInt(((HttpServletRequest)pageContext.getRequest()).getParameter("srhid")); } catch(Exception ignore) { }

            line.append("<input class='cv_insr' type=text name=Search value='").append(h_search).append("' onClick='cv_clr_in();return false;' />");
            line.append("</td><td>");
            line.append("<select class='cv_slkt' name='srhid'>");
            line.append("<option value=1 ").append(searchID == 1 ? "selected='selected'" : "").append("/>B2B Items Title");
            line.append("<option value=2 ").append(searchID == 2 ? "selected='selected'" : "").append("/>ALL Items Title");
            line.append("<option value=3 ").append(searchID == 3 ? "selected='selected'" : "").append("/>B2B Items Advanced");
            line.append("<option value=4 ").append(searchID == 4 ? "selected='selected'" : "").append("/>ALL Items Advanced");
//            line.append("<option value=5 ").append(searchID == 5 ? "selected='selected'" : "").append("/>Hot Deals");
            line.append("</select>");
            line.append("</td>");
            line.append("<td><a class='cv_lgo' href='#' onClick='cv_srch_go();return false;'></a></td>");
            line.append("</tr>");
            line.append("</table>");
            if(pageName != null && pageName.length() != 0) {
                line.append("<table id='cv_g_head'>");
                line.append("<tr><th>").append(pageName.toUpperCase()).append("</th></tr>");
                line.append("</table>");
            }
            line.append("</form>");
            line.append("</div>\n");


            pageContext.getOut().print(line.toString());
        }
        catch(java.io.IOException e) {
            throw new JspTagException("com.compuvest.tgl.Head: " + e.getMessage());
        }

        return SKIP_BODY;
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="doEndTag()">

    @Override
    public int doEndTag() {
        return EVAL_PAGE;
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="release()">

    @Override
    public void release() {
        pageName = null;
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="setPageName()">

    public void setPageName(String pageName) {
        this.pageName = pageName;
    }
// </editor-fold>

}
